<template>
  <base-breadcrumb class="UpdateArchiveStandingBook-container" :title="breadcrumbTitle">
    <a-card :bordered="false">
      <title-name title="基本信息" />
      <custom-form ref="baseInfoForm" editModel="V" :isValidate="true" :form="baseInfo" :formList="baseInfoList" />
    </a-card>
    <a-card :bordered="false">
      <title-name title="归档项目" />
      <s-table
        ref="table"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
        bordered
      >
        <template slot="actualArchiveTime" slot-scope="text">
          {{ text || '—' }}
        </template>
        <template slot="ifCheckArchive" slot-scope="text, record">
          <!-- 当资料审核状态为通过时，为已归档，其余情况为未归档 -->
          <span v-if="record.archiveDataStatus == 2">是</span>
          <span v-else style="color: red">否</span>
        </template>
        <template slot="ifOver" slot-scope="text">
          <span v-if="text" style="color: red">是</span>
          <span v-else>否</span>
        </template>
        <template slot="ifArchiveExtendedApply" slot-scope="text">
          <span v-if="text" style="color: red">是</span>
          <span v-else>否</span>
        </template>
        <template slot="archiveDataStatus" slot-scope="text, record">
          <status-display :statusCode="text" isApproval />
        </template>
        <template slot="action" slot-scope="text, record">
          <div class="pub-table-list-action">
            <span @click="handleUpdate(record, 'look')">查看</span>
          </div>
        </template>
      </s-table>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <a-button class="ml12" type="default" @click="handleClose">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import { getArchiveDocList } from '@/api/office/archiveManage/archiveDoc.js'
import StatusDisplay from '@/components/StatusDisplay'

const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    },
  },
  {
    title: '分公司',
    dataIndex: 'branchOrgName',
  },
  {
    title: '项目',
    dataIndex: 'projectName',
    ellipsis: true,
  },
  {
    title: '开工日期',
    dataIndex: 'startWorkingTime',
  },
  {
    title: '竣工日期',
    dataIndex: 'completionTime',
  },
  {
    title: '计划归档日期',
    dataIndex: 'archiveTime',
  },
  {
    title: '实际归档日期',
    dataIndex: 'actualArchiveTime',
    scopedSlots: { customRender: 'actualArchiveTime' },
  },
  {
    title: '是否已归档',
    dataIndex: 'ifCheckArchive',
    scopedSlots: { customRender: 'ifCheckArchive' },
  },
  {
    title: '是否已超期',
    dataIndex: 'ifOver',
    scopedSlots: { customRender: 'ifOver' },
  },
  {
    title: '是否申请延期归档',
    dataIndex: 'ifArchiveExtendedApply',
    scopedSlots: { customRender: 'ifArchiveExtendedApply' },
  },
  {
    title: '归档资料状态',
    dataIndex: 'archiveDataStatus',
    scopedSlots: { customRender: 'archiveDataStatus' },
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '70px',
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]

export default {
  name:'a'+Date.now(),
  components: {
    STable,
    StatusDisplay,
  },
  data() {
    return {
      baseInfo: {},
      baseInfoList: [
        {
          label: '分公司',
          keyName: 'branchOrgName',
          type: 'BaseInput',
          disabled: true,
        },
        {
          label: '归档年度',
          keyName: 'archiveYear',
          type: 'BaseInput',
          disabled: true,
        },
      ],
      columns: columns,
    }
  },
  computed: {
    breadcrumbTitle() {
      const map = {
        look: '竣工项目归档台账详情',
      }
      return map[this.pageType] || map['look']
    },
  },
  created() {
    this.initPage()
  },
  methods: {
    initPage() {
      const { branchOrgName, archiveYear } = this.$route.query
      this.baseInfo = {
        branchOrgName,
        archiveYear,
      }
    },
    handleUpdate(data, pageType) {
      const actionMap = {
        look: () => {
          this.$router.push({
            path: '/conference/archiveManage/archiveDoc/update',
            query: {
              id: data.id || '',
              pageType: pageType,
              archiveTime: data.archiveTime || '',
              projectId: data.projectId || '',
              ignoreNoTab: 1,
              history: JSON.stringify([
                {
                  title: '竣工项目归档',
                  path: '/conference/archiveManage/archiveDoc',
                },
                {
                  title: '竣工项目归档',
                  path: '/conference/archiveManage/archiveDoc/update',
                }
              ]),
            },
          })
        },
      }
      actionMap[pageType] && actionMap[pageType]()
    },
    loadData(parameter) {
      const requestParameters = Object.assign(
        {},
        { ...parameter },
        { query: { ...this.queryParam, branchOrgId: this.$route.query.branchOrgId, archiveYear: this.$route.query.archiveYear } }
      )
      return getArchiveDocList(requestParameters)
    },
    handleClose() {
      this.$close()
    },
  },
}
</script>

<style>
</style>